<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/views/pagelet/page-includes.jsp"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"
	name="viewport">
</head>
<body class="hold-transition skin-blue sidebar-mini">
			<section class="content" style="align-content: center">
<!-- 内容开始 -->
				<div>
					<form class="form-horizontal">
						<div class="box-body">
							<div class="form-group bs-valid rowStyle">
								<label for="groupName" class="control-label">用户组名: </label>
								<input type="text" class="form-control" id="groupName" name="groupName" value="${sysGroup.groupName }">
							</div>
							<div class="form-group bs-valid rowStyle">
								<label for="orgName" class="control-label">所属机构: </label>
								<input type="text" class="form-control" onclick="showMenu('orgName');" id="orgName" name="orgName" value="${sysGroup.orgName }">
							</div>
							<div class="form-group bs-valid rowStyle">
								<label for="remark" class="control-label">备注: </label>
								<input type="text" class="form-control" id="remark" name="remark" value="${sysGroup.remark }">
							</div>
						</div>
						<div class="box-footer text-center">
							<input type="hidden" id="orgCode" name="orgCode" value="${sysGroup.orgCode }" />
							<input type="hidden" id="id" name="id" value="${sysGroup.id }" />
							<button type="button" class="btn btn-primary saveBtn" onclick="save()">保存</button>
						</div>
					</form>
				</div>
				<div id="treeDiv" class="treeDiv" style="display:none; position: absolute;">
					<ul id="treeUl" class="ztree" style="margin-top:0; width:160px;"></ul>
				</div>
<!-- 内容结束 -->
			</section>
</body>

<script type="text/javascript">

var index = parent.layer.getFrameIndex(window.name);

onload = function(){
	var id = "${sysDict.id }";
	if(id != null && id != ""){
		$("#dictCode").attr({"disabled":"disabled"});
	}
	
	//机构树
	var setting = {
		view: {
			selectedMulti: false
		},
		async: {
			enable: true,
			url:"${webroot}/sysorg/getjsondata",
		},
		data: {
			simpleData: {
				enable: true
			}
		},
		callback: {
			onClick: onClickTree
		}
	};
	$.fn.zTree.init($("#treeUl"), setting);
	
	//添加校验表单
	$('.form-horizontal').bootstrapValidator({
		message: '输入错误',
		feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
        	groupName : {
        		validators : {
        			notEmpty: {message: '用户组名称不能为空'},
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{1,100}$/,message: '用户组名称为1~100个字符，不能包含特殊字符'}
        		}
        	},
        	orgName : {
        		validators : {
        			notEmpty: {message: '所属机构不能为空'}
        		}
        	},
        	remark : {
        		validators : {
                    regexp: {regexp: /^[a-zA-Z0-9_\u4e00-\u9fa5]{0,200}$/,message: '备注不能超过200个字符，不能包含特殊字符'}
        		}
        	}
        }
	})
}



function save() {
	$('.form-horizontal').bootstrapValidator('validate');
	if(!$('.form-horizontal').data('bootstrapValidator').isValid()) return;
	var id = "${sysGroup.id}";
	var flag = "";
	if(id != null && id != ""){
		flag = "UPDATE";
	}
	$.ajax({
		type: "POST",
		url: webroot + "/sysgroup/modify?showtype=" + flag,
		data:$('.form-horizontal').serialize(),
		dataType: "json",
		success: function(resp){
			if(resp.success){
				app.print.success("保存成功!", index,null)
			} else {
				app.print.error(resp.message, null, null);
			}
		}
	});
}

function onClickTree(e, treeId, treeNode) {
	var zTree = $.fn.zTree.getZTreeObj("treeUl"),
	nodes = zTree.getSelectedNodes(),
	name = "";
	value = "";
	nodes.sort(function compare(a,b){return a.id-b.id;});
	for (var i=0, l=nodes.length; i<l; i++) {
		value += nodes[i].id + ",";
		name += nodes[i].name + ",";
	}
	if (value.length > 0 ) value = value.substring(0, value.length-1);
	if (name.length > 0 ) name = name.substring(0, name.length-1);
	
	$("#orgName").val(name);
	$("#orgCode").val(value);
	
	hideMenu();
}
</script>

</html>
